﻿using System;

namespace SampleCode.VirtualFS
{
    /// <summary>
    /// A public wrapper for FsInternalFileInfo, to be returned in a collection
    /// </summary>
    public class FsFileInfo
    {
        /// <summary>
        /// Internal file info
        /// </summary>
        private readonly FsInternalFileInfo _internalInfo;
        
        /// <summary>
        /// Internal ctor
        /// </summary>
        /// <param name="name">File name</param>
        /// <param name="fullName">File path</param>
        /// <param name="internalInfo">Internal file info</param>
        internal FsFileInfo(string name, string fullName, FsInternalFileInfo internalInfo)
        {
            Name = name;
            FullName = fullName;
            _internalInfo = internalInfo;
        }

        /// <summary>
        /// Internal ctor used for events
        /// </summary>
        /// <param name="fullName">File path</param>
        /// <param name="internalInfo">Internal file info</param>
        internal FsFileInfo(string fullName, FsInternalFileInfo internalInfo)
        {
            FullName = fullName;
            int pos = FullName.LastIndexOf(FsDisk.ExternalPathSeparator);
            Name = pos < 0 ? FullName : FullName.Substring(pos + 1);
            _internalInfo = internalInfo;
        }

        // Public properties

        public string Name              { get; private set; }
        public string FullName          { get; private set; }
        public DateTime TimeCreated     { get { return _internalInfo.TimeCreated; } }
        public DateTime TimeModified    { get { return _internalInfo.TimeModified; } }
        public int Length               { get { return _internalInfo.Length; } }

        public override string ToString()
        {
            return string.Format
            (
                "{0} (Length: {1}, Created: {2}, Modified: {3})",
                Name,
                Length,
                TimeCreated,
                TimeModified
            );
        }
    }
}
